// Copyright (c) Microsoft Corporation.  All rights reserved.

#include "stdafx.h"
#include "D3D10EffectVectorVariable.h"

using namespace Microsoft::WindowsAPICodePack::DirectX::Direct3D10;

array<Boolean>^ EffectVectorVariable::GetBoolVector()
{
    array<Boolean>^ arr = gcnew array<Boolean>(4);
    pin_ptr<Boolean> pArr = &arr[0];

    CommonUtils::VerifyResult(GetInterface<ID3D10EffectVectorVariable>()->GetBoolVector((BOOL*)pArr));

    return arr;
}

array<Boolean, 2>^ EffectVectorVariable::GetBoolVectorArray(UInt32 count)
{
    array<Boolean, 2>^ arr = gcnew array<Boolean, 2>(4, count);
    pin_ptr<Boolean> pArr = &arr[0, 0];

    CommonUtils::VerifyResult(GetInterface<ID3D10EffectVectorVariable>()->GetBoolVectorArray((BOOL*) pArr, 0, static_cast<UINT>(count)));

    return arr;
}

array<Single>^ EffectVectorVariable::GetFloatVector()
{
    array<Single>^ arr = gcnew array<Single>(4);
    pin_ptr<Single> pArr = &arr[0];

    CommonUtils::VerifyResult(GetInterface<ID3D10EffectVectorVariable>()->GetFloatVector(pArr));

    return arr;
}

array<Single, 2>^  EffectVectorVariable::GetFloatVectorArray(UInt32 count)
{
    array<Single, 2>^ arr = gcnew array<Single, 2>(4, count);
    pin_ptr<FLOAT> pArr = &arr[0, 0];

    CommonUtils::VerifyResult(GetInterface<ID3D10EffectVectorVariable>()->GetFloatVectorArray(pArr, 0, static_cast<UINT>(count)));

    return arr;
}

array<Int32>^ EffectVectorVariable::GetIntVector()
{
    array<Int32>^ arr = gcnew array<Int32>(4);
    pin_ptr<int> pArr = &arr[0];

    CommonUtils::VerifyResult(GetInterface<ID3D10EffectVectorVariable>()->GetIntVector(pArr));

    return arr;
}

array<Int32, 2>^  EffectVectorVariable::GetIntVectorArray(UInt32 count)
{
    array<Int32, 2>^ arr = gcnew array<Int32, 2>(4, count);
    pin_ptr<int> pArr = &arr[0, 0];

    CommonUtils::VerifyResult(GetInterface<ID3D10EffectVectorVariable>()->GetIntVectorArray(pArr, 0, static_cast<UINT>(count)));

    return arr;
}

void EffectVectorVariable::SetBoolVector(array<Boolean>^ data)
{
    if (data == nullptr || data->Length != 4)
    {
        throw gcnew ArgumentException("data", "Must be a valid array of length = 4.");
    }

    pin_ptr<Boolean> pArr = &data[0];
    CommonUtils::VerifyResult(GetInterface<ID3D10EffectVectorVariable>()->SetBoolVector((BOOL*)pArr));
}

void EffectVectorVariable::SetBoolVectorArray(array<Boolean, 2>^ data)
{
    if (data == nullptr)
    {
        throw gcnew ArgumentNullException("data", "Must be a valid array.");
    }

    UINT count = static_cast<UINT>(data->Rank);
    pin_ptr<Boolean> pArr = &data[0, 0];
    CommonUtils::VerifyResult(GetInterface<ID3D10EffectVectorVariable>()->SetBoolVectorArray((BOOL*)pArr, 0, count));
}

void EffectVectorVariable::SetFloatVector(array<Single>^ data)
{
    if (data == nullptr || data->Length != 4)
    {
        throw gcnew ArgumentException("data", "Must be a valid array of length = 4.");
    }

    pin_ptr<FLOAT> dataArray = &data[0];
    CommonUtils::VerifyResult(GetInterface<ID3D10EffectVectorVariable>()->SetFloatVector(dataArray));
}

void EffectVectorVariable::SetFloatVectorArray(array<Single, 2>^ data)
{
    if (data == nullptr)
    {
        throw gcnew ArgumentNullException("data", "Must be a valid array.");
    }

    UINT count = static_cast<UINT>(data->Rank);
    pin_ptr<FLOAT> pArr = &data[0, 0];

    CommonUtils::VerifyResult(GetInterface<ID3D10EffectVectorVariable>()->SetFloatVectorArray(pArr, 0, count));
}

void EffectVectorVariable::SetIntVector(array<Int32>^ data)
{
    if (data == nullptr || data->Length != 4)
    {
        throw gcnew ArgumentException("data", "Must be a valid array of length = 4.");
    }

    pin_ptr<int> pArr = &data[0];
    CommonUtils::VerifyResult(GetInterface<ID3D10EffectVectorVariable>()->SetIntVector(pArr));
}

void EffectVectorVariable::SetIntVectorArray(array<Int32, 2>^ data)
{
    if (data == nullptr)
    {
        throw gcnew ArgumentNullException("data", "Must be a valid array.");
    }

    UINT count = static_cast<UINT>(data->Rank);
    pin_ptr<int> pArr = &data[0, 0];

    CommonUtils::VerifyResult(GetInterface<ID3D10EffectVectorVariable>()->SetIntVectorArray(pArr, 0, count));
}

